package com.java.example.util

import android.content.Context
import android.util.TypedValue
import com.java.example.app.MyApplication

object DimenUtil {
    @JvmStatic
    val screenWidth: Int
        get() {
            val resources = MyApplication.sInstance.applicationContext.resources
            val dm = resources.displayMetrics
            return dm.widthPixels
        }

    val screenHeight: Int
        get() {
            val resources = MyApplication.sInstance.applicationContext.resources
            val dm = resources.displayMetrics
            return dm.heightPixels
        }

    fun dp2px(context: Context, dp: Float): Int {
        return TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, dp,
                context.resources.displayMetrics
        ).toInt()
    }

    private fun sp2px(context: Context, sp: Float): Int {
        return TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_SP, sp,
                context.resources.displayMetrics
        ).toInt()
    }
}
